<?php
require_once 'config.php';
require_once 'function.php';
require_once 'class/Mysql.class.php';
$db = new Mysql();

$kid = get('kid');
$type = get('type');
$table = get('table');
$field = get('field');

switch( $type ){
	case 'article':
		$data = $db->getOne( 'topic_article', 'ar_id='.$kid, 'ar_title, ar_subtitle, ar_introduction, ar_content, ar_page_keyword, ar_page_description');
	break;
	case 'table':
		$data = $db->getOne( 'Table_'.$table, 'D_ID='.$kid, $field);
	break;
	case 'product':
		$data = $db->getOne( 'product', 'product_id='.$kid, 'product_support_content,product_ad,product_intro,product_content,product_key_feature,product_guide_content,techspec_content_table,product_contrast_table');
	break;
	case 'won_product':
		$data = $db->getOne( 'won_product', 'id='.$kid, 'advantages_content,tips,ad_guide');
		break;
	case 'feature':
		$data = $db->getOne( 'feature', 'feature_id='.$kid, 'feature_title,feature_intro');
		break;
	case 'product_page':
		$data = $db->getOne( 'product_page', 'page_id='.$kid, 'page_title,page_content');
		break;
	case 'category':
		$data = $db->getOne( 'category', 'cat_id='.$kid, 'cat_desc');
		break;
}

//print_r( $data );exit;

//设置要翻译成的语言
$language_to = 'br';
setcookie('googtrans', '/en/'.language_convert('google',$language_to));

echo '<html><body>';

$tr_items = $html = '';

foreach( $data as $k=>$v ){
	if( empty( $v ) || (int)$v ) continue;//空数据或数字不翻译
	$html .= '<div class="tr_item_div" id="'.$k.'">'.$v.'</div>'."\r\n\r\n\r\n";//用于页面翻译
	$tr_items .= '<input type="hidden" name="tr['.$k.']" id="tr_item_'.$k.'" />';//用于提交翻译结果
}

if( $html == '' ){
	echo '<script type="text/javascript">parent.no();</script>';
	exit;
}


//注释html页面中的object,js,iframe,img，在生成时要去掉注释
$html = str_replace('<object', '<!--[--<object', $html );
$html = str_replace('</object>', '</object>--]-->', $html );
$html = str_replace('<script', '<!--[--<script', $html );
$html = str_replace('</script>', '</script>--]-->', $html );
$html = str_replace('<iframe', '<!--[--<iframe', $html );
$html = str_replace('</iframe>', '</iframe>--]-->', $html );
$html = preg_replace('/<link([^>]+)>/iU', '<!--[--<link$1>--]-->', $html );
$html = preg_replace('/<img([^>]+)>/iU', '<!--[--<img$1>--]-->', $html );

//更改页面中的font标签，因为google和微软翻译会造成大量font标签，更改是为了区分，在create.php中要还原
$html = str_replace('<font', '<s-font', $html );
$html = str_replace('</font>', '</s-font>', $html );

//注释过滤词，这样google不会翻译，在create.php去掉注释.注：用下标防止注释中再被注释
foreach( $product_name as $k=>$v ){
	$html = str_replace( $v, '0-'.$k.'-0', $html );
}

echo $html;

$s = '<div id="remove">
<form id="t_form" method="post" action="create.php" style="display:none;">';
$s .= $tr_items;
$s .= '<input type="hidden" name="language_to" value="'.$language_to.'" />
<input type="hidden" name="kid" value="'.$kid.'" />
<input type="hidden" name="type" value="'.$type.'" />
<input type="hidden" name="table" value="'.$table.'" />
<input type="submit" />
</form>';


$s .= '<script type="text/javascript" src="js/element.js?cb=googleTranslateElementInit"></script>
<script type="text/javascript" src="js/jquery-1.6.2.js"></script>
<script type="text/javascript" src="js/tr.js"></script>
</div>';
echo $s;

echo '</body></html>';

?>